using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Xml;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace MenuGame2DXNA
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;

        public GraphicsDeviceManager Graphics
        {
            get { return graphics; }
            set { graphics = value; }
        }
        SpriteBatch spriteBatch;

        public SpriteBatch SpriteBatch
        {
            get { return spriteBatch; }
            set { spriteBatch = value; }
        }
       
        private int scene;

        public int Scene
        {
            get { return scene; }
            set 
            { 
                scene = value;
                if (listScene[scene].State == SceneState.PAUSE)
                    listScene[scene].Resume();
                if (listScene[scene].State == SceneState.STOP)
                    listScene[scene].Play();
            }
        }
        /// <summary>
        /// Gets or sets the sound manager.
        /// </summary>
        /// <value>
        /// The sound manager.
        /// </value>
        public SoundManager soundManager { get; set; }
        /// <summary>
        /// Gets or sets the music manager.
        /// </summary>
        /// <value>
        /// The music manager.
        /// </value>
        public MusicManager musicManager { get; set; }

        /// <summary>
        /// 
        /// </summary>
        private List<Scene> listScene;

        public List<Scene> ListScene
        {
            get { return listScene; }
            set { listScene = value; }
        }
        public int IDColor { get; set; }
        public int ScorePlayer { get; set; }
        public Game()
        {
            ScorePlayer = 0;
            IDColor = 0;
            graphics = new GraphicsDeviceManager(this);
            
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
            Content.RootDirectory = "Content";
            
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            this.IsMouseVisible = true;
            listScene = new List<Scene>();
            listScene.Add(new sMenu());
            listScene.Add(new sMainGame());
            listScene.Add(new sOptions());
            listScene.Add(new sCredits());
            listScene.Add(new sTrailer());
            listScene.Add(new sHighScore());
            listScene.Add(new sChoosePlayer());
            listScene.Add(new sInputName());
            listScene.Add(new sHelp());
            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here


            soundManager = new SoundManager();
            soundManager.LoadContent(Content);
            musicManager = new MusicManager();
            musicManager.LoadContent(Content);
            
            //Play the sound
           // MusicManager.Play("backSound");
            
            scene = 4;
            foreach(Scene Sc in listScene)
            {
                Sc.LoadContent(this);
            }
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

    
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        
        protected override void Update(GameTime gameTime)
        {
            
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            listScene[scene].Update(gameTime);
            base.Update(gameTime);
        }

        

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            
            // TODO: Add your drawing code here
            spriteBatch.Begin();
            listScene[scene].Draw(gameTime,spriteBatch);
            
            spriteBatch.End();
            base.Draw(gameTime);
        }
       
        
        

       
        
    }
}

        
 
